#!/usr/bin/env node

console.error('=== ECHO TEST START ===');
console.error('Node.js path:', process.execPath);
console.error('Current working directory:', process.cwd());
console.error('Script arguments:', process.argv);
console.error('Environment variables:', Object.keys(process.env).slice(0, 5));

// 立即输出到stdout
console.log('{"status": "started", "pid": ' + process.pid + '}');

// 监听stdin输入
process.stdin.on('data', (data) => {
  console.error('Received input:', data.toString());
  console.log('Echo:', data.toString());
});

process.stdin.on('end', () => {
  console.error('=== ECHO TEST END ===');
  process.exit(0);
});

// 错误处理
process.on('uncaughtException', (error) => {
  console.error('Uncaught exception:', error);
  process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
  console.error('Unhandled rejection:', reason);
  process.exit(1);
});